#!/bin/bash

set -ex

source /etc/profile

host=$(cat /vagrant/conf/development/server_host)

service tomcat7 stop
service bbb-red5 stop

rm -rf /var/lib/tomcat7/webapps/bigbluebutton*
cp /bigbluebutton/bigbluebutton-web/target/bigbluebutton-0.9.0.war /var/lib/tomcat7/webapps/bigbluebutton.war
unzip /var/lib/tomcat7/webapps/bigbluebutton.war -d /var/lib/tomcat7/webapps/bigbluebutton
ASJ_SECURITY_SALT=$(cat /vagrant/conf/development/asj_security_salt)
sed -i "s/asjSecuritySalt=.*/asjSecuritySalt=${ASJ_SECURITY_SALT}/" /var/lib/tomcat7/webapps/bigbluebutton/WEB-INF/classes/bigbluebutton.properties
sed -i "s/aotrs.host=.*/aotrs.host=${host}/" /var/lib/tomcat7/webapps/bigbluebutton/WEB-INF/classes/bigbluebutton.properties

bbb-conf --clean --setip ${host} --setsecret $(cat /vagrant/conf/development/security_salt)
